<?php

require_once("lib/mysql.class.php");


class DBLogger
{
	private static $instance = null;
	private $db = null;

	public static function getInstance()
	{
		if ( self::$instance == null )
		{
			self::$instance = new DBLogger();
		}
		
		return self::$instance;
	}
	
	private function __construct()
	{
		$this->db = MySQL::getInstance();
	}
	
	public function Write($transact_id, $code, $msg = null, $provider_id = null, $addr = '0.0.0.0')
	{
		$dt = date("Y-m-d H:i:s", time());
		$sql = "INSERT INTO payment_log(transact_id, addr, code, provider_id, raw_data) VALUES(%s, %s, %s, %s, %s)";
		
		$params = array(
			$this->db->escape($transact_id),
			$this->db->escape($addr),
			$this->db->escape($code),
			$this->db->escape($provider_id),
			$this->db->escape(htmlspecialchars($msg))
			);
		$sql = vsprintf($sql, $params);
		
		$this->db->query($sql);
	}
}
